use QThread::usleep instead of our own function. (#277)
authortsteven4 <tsteven4@users.noreply.github.com>
Wed, 28 Nov 2018 14:00:10 +0000 (07:00 -0700)
committerGitHub <noreply@github.com>
Wed, 28 Nov 2018 14:00:10 +0000 (07:00 -0700)
Our test suite doesn't test sleep, but the nmea pause option
can be used on write to verify functionality interactively.

14 files changed:
CMakeLists.txt
GPSBabel.pro
Makefile.in
config.h.in
configure
configure.ac
defs.h
garmin_gpi.cc
gbsleep.cc [deleted file]
jeeps/gpsserial.cc
mtk_logger.cc
navilink.cc
nmea.cc
skytraq.cc

index 111fda093bcbd289e99290740ce93d5272b566ef..cd824e6a5662063528ed40f971a05263c8389ce6 100644 (file)
@@ -94,7 +94,7 @@ set(SUPPORT
   queue.cc route.cc waypt.cc filter_vecs.cc util.cc vecs.cc mkshort.cc
   csv_util.cc strptime.c grtcirc.cc util_crc.cc xmlgeneric.cc
   formspec.cc xmltag.cc cet.cc cet_util.cc fatal.cc rgbcolors.cc
-  inifile.cc garmin_fs.cc gbsleep.cc units.cc gbser.cc
+  inifile.cc garmin_fs.cc units.cc gbser.cc
   gbfile.cc parse.cc session.cc main.cc globals.cc
   src/core/usasciicodec.cc
   src/core/xmlstreamwriter.cc 
@@ -186,7 +186,7 @@ if(UNIX)
   if(${HAVE_STDARG_H})
     add_definitions(-DHAVE_STDARG_H)
   endif()
-  add_definitions(-DHAVE_NANOSLEEP -DHAVE_LIBUSB -DHAVE_GLOB)
+  add_definitions(-DHAVE_LIBUSB -DHAVE_GLOB)
   set(SOURCES ${SOURCES} gbser_posix.cc)
   set(HEADERS ${HEADERS} gbser_posix.h)
   set(JEEPS ${JEEPS} jeeps/gpslibusb.cc)
index ecf10d070f5f4d4c71a63d0426cd3dee6d723139..a5adff197e27354ccb1d49ac21f78a09218f916d 100644 (file)
@@ -79,7 +79,7 @@ JEEPS += jeeps/gpsapp.cc jeeps/gpscom.cc \
 SUPPORT = queue.cc route.cc waypt.cc filter_vecs.cc util.cc vecs.cc mkshort.cc \
           csv_util.cc strptime.c grtcirc.cc util_crc.cc xmlgeneric.cc \
           formspec.cc xmltag.cc cet.cc cet_util.cc fatal.cc rgbcolors.cc \
-          inifile.cc garmin_fs.cc gbsleep.cc units.cc gbser.cc \
+          inifile.cc garmin_fs.cc units.cc gbser.cc \
           gbfile.cc parse.cc session.cc main.cc globals.cc \
           src/core/usasciicodec.cc \
           src/core/xmlstreamwriter.cc 
@@ -169,7 +169,7 @@ macx|linux {
     # this is used by zlib
     DEFINES += HAVE_STDARG_H
   }
-  DEFINES += HAVE_NANOSLEEP HAVE_LIBUSB HAVE_GLOB
+  DEFINES += HAVE_LIBUSB HAVE_GLOB
   SOURCES += gbser_posix.cc
   HEADERS += gbser_posix.h
   JEEPS += jeeps/gpslibusb.cc
index d4dbfcf47e7d4f9d0a0ae17e68ff6744a4439f67..ff2126c1f47615844b33f0d492be44bb06468684 100644 (file)
@@ -119,7 +119,7 @@ ZLIB=zlib/adler32.o zlib/compress.o zlib/crc32.o zlib/deflate.o zlib/inffast.o \
 LIBOBJS = queue.o route.o waypt.o filter_vecs.o util.o vecs.o mkshort.o \
           csv_util.o strptime.o grtcirc.o util_crc.o xmlgeneric.o \
           formspec.o xmltag.o cet.o cet_util.o fatal.o rgbcolors.o \
-         inifile.o garmin_fs.o gbsleep.o units.o @GBSER@ gbser.o \
+         inifile.o garmin_fs.o units.o @GBSER@ gbser.o \
          gbfile.o parse.o session.o \
          src/core/xmlstreamwriter.o \
          src/core/usasciicodec.o\
@@ -587,7 +587,6 @@ gbser.o: gbser.cc defs.h config.h queue.h zlib/zlib.h zlib/zconf.h \
 gbser_posix.o: gbser_posix.cc defs.h config.h queue.h zlib/zlib.h \
   zlib/zconf.h gbfile.h cet.h inifile.h session.h src/core/datetime.h \
   src/core/optional.h gbser.h gbser_private.h
-gbsleep.o: gbsleep.cc config.h
 gdb.o: gdb.cc defs.h config.h queue.h zlib/zlib.h zlib/zconf.h gbfile.h \
   cet.h inifile.h session.h src/core/datetime.h src/core/optional.h \
   cet_util.h csv_util.h garmin_fs.h jeeps/gps.h jeeps/../defs.h \
index f553d85204c6413af09e782508734d7970ba07b8..9e84d0f3a48188dcc24051cb533afbcb7a4a659a 100644 (file)
@@ -9,8 +9,8 @@
 /* 1 to enable all the filters. */
 #undef FILTERS_ENABLED
 
-/* define if the compiler supports basic C++11 syntax */
-#undef HAVE_CXX11
+/* define if the compiler supports basic C++14 syntax */
+#undef HAVE_CXX14
 
 /* Define to 1 if you have the `glob' function. */
 #undef HAVE_GLOB
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
 
-/* Define to 1 if you have the `nanosleep' function. */
-#undef HAVE_NANOSLEEP
-
-/* Define to 1 if you have the `sleep' function. */
-#undef HAVE_SLEEP
-
 /* Define to 1 if you have the <stdarg.h> header file. */
 #undef HAVE_STDARG_H
 
index b03f035e30ea71483a50d480026392dafd6ad543..d857f9dd40bc5366a9f3fa2bc82cc5044516e6a2 100755 (executable)
--- a/configure
+++ b/configure
@@ -6751,7 +6751,7 @@ done
 # AC_FUNC_STRTOD
 # AC_FUNC_VPRINTF
 # AC_CHECK_FUNCS([atexit floor localtime_r memmove memset pow select sqrt strchr strcspn strdup strerror strncasecmp strrchr strspn strstr strtol strtoul])
-for ac_func in nanosleep sleep uname glob
+for ac_func in uname glob
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_cxx_check_func "$LINENO" "$ac_func" "$as_ac_var"
index 801514164d575bc0ccb973a8a0549de8fb443e74..4e0d38716a55a29fe8012dc546e17cb8c9eafa94 100644 (file)
@@ -426,7 +426,7 @@ AC_CHECK_HEADERS([unistd.h stdarg.h])
 # AC_FUNC_STRTOD
 # AC_FUNC_VPRINTF
 # AC_CHECK_FUNCS([atexit floor localtime_r memmove memset pow select sqrt strchr strcspn strdup strerror strncasecmp strrchr strspn strstr strtol strtoul])
-AC_CHECK_FUNCS([nanosleep sleep uname glob])
+AC_CHECK_FUNCS([uname glob])
 
 #
 # There's probably some more "autoconfish" way to do this.
diff --git a/defs.h b/defs.h
index b4aa31267ec6fb124abb2baa4f7c642c59e850d4..068faf289c1404cbdbc033ba14154feaf01f0269 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -1186,11 +1186,6 @@ double fmt_distance(const double, const char** tag);
 double fmt_altitude(const double, const char** tag);
 double fmt_speed(const double, const char** tag);
 
-/*
- * From gbsleep.c
- */
-void gb_sleep(unsigned long microseconds);
-
 /*
  * From nmea.c
  */
index f60092a04e9718fad501024bb3d87ab3fbc47afa..028c85c69d24576c1c82e820701a7264013b5f66 100644 (file)
@@ -50,6 +50,7 @@
 #include "garmin_gpi.h"
 #include "jeeps/gpsmath.h"
 #include <QtCore/QTextCodec>
+#include <QtCore/QThread>
 #include <cstdlib>
 
 #define MYNAME "garmin_gpi"
@@ -1573,7 +1574,7 @@ garmin_gpi_wr_deinit()
     }
     gpi_timestamp += sleep;
     while (gpi_timestamp > time(nullptr)) {
-      gb_sleep(100);
+      QThread::usleep(100);
     }
   }
 }
diff --git a/gbsleep.cc b/gbsleep.cc
deleted file mode 100644 (file)
index 25da77f..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
-    OS abstraction to sleep a given number of milliseconds.
-
-    Copyright (C) 2006 Robert Lipe, robertlipe+source@gpsbabel.org
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
-
- */
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#if __WIN32__
-
-#include <windows.h>
-void
-gb_sleep(unsigned long microseconds)
-{
-  Sleep(microseconds/1000 + 1);
-}
-
-#elif defined HAVE_NANOSLEEP
-
-#include <ctime>
-void
-gb_sleep(unsigned long microseconds)
-{
-  struct timespec req;
-  req.tv_sec  = microseconds / 1000000;
-  req.tv_nsec = (microseconds * 1000) % 1000000000;
-  nanosleep(&req, nullptr);
-}
-#elif defined HAVE_SLEEP
-/* Amazingly underachieving, but probably "good enough" */
-#include <unistd.h>
-void
-gb_sleep(unsigned long microseconds)
-{
-  sleep(microseconds / 1000000);
-}
-#endif
index 2ccd1f3024320e63ac181f24a6e05c9ea51f6686..26343a89b860aca5f95819dc82c34f708b82a94d 100644 (file)
@@ -26,6 +26,7 @@
 #include "gps.h"
 #include "../gbser.h"
 #include "gpsserial.h"
+#include <QtCore/QThread>
 #include <cerrno>
 #include <cstdio>
 #include <ctime>
@@ -235,7 +236,7 @@ int32 GPS_Serial_Set_Baud_Rate(gpsdevh* fd, int br)
   GPS_PPacket tra;
   GPS_PPacket rec;
   win_serial_data* wsd = (win_serial_data*)fd;
-  
+
   DWORD speed = mkspeed(br);
 
   // Turn off all requests by transmitting packet
@@ -247,7 +248,7 @@ int32 GPS_Serial_Set_Baud_Rate(gpsdevh* fd, int br)
   if (!GPS_Get_Ack(fd, &tra, &rec)) {
     return gps_errno;
   }
-  
+
   GPS_Util_Put_Int(data, br);
   GPS_Make_Packet(&tra, 0x30, data, 4);
   if (!GPS_Write_Packet(fd,tra)) {
@@ -268,11 +269,11 @@ int32 GPS_Serial_Set_Baud_Rate(gpsdevh* fd, int br)
   }
   GPS_Device_Flush(fd);
   GPS_Device_Wait(fd);
-  
+
   // Sleep for a small amount of time, about 100 milliseconds,
   // to make sure the packet was successfully transmitted to the GPS unit.
-  gb_sleep(100000); 
-  
+  QThread::usleep(100000);
+
   // Change port speed
   DCB tio;
   tio.DCBlength = sizeof(DCB);
@@ -302,10 +303,10 @@ int32 GPS_Serial_Set_Baud_Rate(gpsdevh* fd, int br)
   if (!GPS_Get_Ack(fd, &tra, &rec)) {
     return gps_errno;
   }
-  
+
   if (global_opts.debug_level >= 1) fprintf(stderr, "Serial port speed set to %d\n", br);
   return 0;
-  
+
 }
 #else
 
@@ -623,7 +624,7 @@ int32 GPS_Serial_Set_Baud_Rate(gpsdevh* fd, int br)
   static UC data[4];
   GPS_PPacket tra;
   GPS_PPacket rec;
-  
+
   speed_t speed = mkspeed(br);
 
   // Turn off all requests by transmitting packet
@@ -635,7 +636,7 @@ int32 GPS_Serial_Set_Baud_Rate(gpsdevh* fd, int br)
   if (!GPS_Get_Ack(fd, &tra, &rec)) {
     return gps_errno;
   }
-  
+
   GPS_Util_Put_Int(data, br);
   GPS_Make_Packet(&tra, 0x30, data, 4);
   if (!GPS_Write_Packet(fd,tra)) {
@@ -656,23 +657,23 @@ int32 GPS_Serial_Set_Baud_Rate(gpsdevh* fd, int br)
   }
   GPS_Device_Flush(fd);
   GPS_Device_Wait(fd);
-  
+
   // Sleep for a small amount of time, about 100 milliseconds,
   // to make sure the packet was successfully transmitted to the GPS unit.
-  gb_sleep(100000); 
-  
+    QThread::usleep(100000);
+
   // Change port speed
   posix_serial_data* psd = (posix_serial_data*)fd;
   tty = psd->gps_ttysave;
-  
+
   cfsetospeed(&tty,speed);
   cfsetispeed(&tty,speed);
-  
+
   if (tcsetattr(psd->fd,TCSANOW|TCSAFLUSH,&tty)==-1) {
     GPS_Serial_Error("SERIAL: tcsetattr error");
     return 0;
   }
-  
+
   GPS_Util_Put_Short(data, 0x3a);
   GPS_Make_Packet(&tra, 0x0a, data, 2);
   if (!GPS_Write_Packet(fd,tra)) {
@@ -690,10 +691,10 @@ int32 GPS_Serial_Set_Baud_Rate(gpsdevh* fd, int br)
   if (!GPS_Get_Ack(fd, &tra, &rec)) {
     return gps_errno;
   }
-  
+
   if (global_opts.debug_level >= 1) fprintf(stderr, "Serial port speed set to %d\n", br);
   return 0;
-  
+
 }
 
 #endif /* __WIN32__ */
index 8095c09ffb5bab3614c5e2ae0a7cdc6e38ecb7d9..00b96396d6d163b51fcbd9391324dd3b5c30c9dc 100644 (file)
@@ -59,6 +59,7 @@
 #include "gbser.h"
 #include <QtCore/QDir>
 #include <QtCore/QFile>
+#include <QtCore/QThread>
 #include <cerrno>
 #include <cmath>
 #include <cstdlib>
@@ -517,11 +518,11 @@ static int mtk_erase()
 
   dbg(1, "Start flash erase..\n");
   do_cmd(CMD_LOG_DISABLE, "PMTK001,182,5,3", nullptr, 1);
-  gb_sleep(10*1000);
+  QThread::usleep(10 * 1000);
 
   // Erase log....
   do_cmd(CMD_LOG_ERASE, "PMTK001,182,6", nullptr, 30);
-  gb_sleep(100*1000);
+  QThread::usleep(100 * 1000);
 
   if ((log_status & 2)) {  // auto-log were enabled before..re-enable log.
     int err = do_cmd(CMD_LOG_ENABLE, "PMTK001,182,4,3", nullptr, 2);
@@ -576,12 +577,12 @@ static void mtk_read()
     fusage = nullptr;
   }
 
-  gb_sleep(10*1000);
+  QThread::usleep(10 * 1000);
   if (true || log_enabled) {
     i = do_cmd(CMD_LOG_DISABLE, "PMTK001,182,5,3", nullptr, 2);
     dbg(3, " ---- LOG DISABLE ---- %s\n", i==0?"Success":"Fail");
   }
-  gb_sleep(100*1000);
+  QThread::usleep(100 * 1000);
 
   unsigned int addr_max = 0;
   // get flash usage, current log address..cmd only works if log disabled.
@@ -716,7 +717,7 @@ mtk_retry:
           if (line[15] != '3') {
             // fixme - we should timeout here when no log data has been received...
             dbg(2, "\nLog req. failed (%c)\n", line[15]);
-            gb_sleep(10*1000);
+            QThread::usleep(10 * 1000);
             retry_cnt++;
             goto mtk_retry;
           }
index cc3b7f165767c6bbc8ca9c73a8ce212f141fb131..229044af05a6fb322e865d7f038820aa6fceef1c 100644 (file)
@@ -26,6 +26,7 @@
 #include "gbser.h"
 #include "jeeps/gpsmath.h"
 #include "navilink.h"
+#include <QtCore/QThread>
 
 #define MYNAME "NAVILINK"
 
@@ -598,7 +599,7 @@ serial_write_track()
   data[6] = 0x00;
 
   write_packet(PID_WRITE_TRACKPOINTS, data, sizeof(data));
-  gb_sleep(10000);
+  QThread::usleep(10000);
   write_packet(PID_DATA, track_data, track_data_ptr - track_data);
   read_packet(PID_CMD_OK, nullptr, 0, 0, false);
 
@@ -1045,7 +1046,7 @@ nuke()
      * takes around 1 second.  The total sectors for SBP is 10.
      * So give the device some time to clear its datalog, in addition
      * to SERIAL_TIMEOUT, which applies to read_packet() */
-    gb_sleep(CLEAR_DATALOG_TIME * 1000);
+    QThread::usleep(CLEAR_DATALOG_TIME * 1000);
     read_packet(PID_ACK, nullptr, 0, 0, false);
   }
 }
diff --git a/nmea.cc b/nmea.cc
index f73deb26f63a7a9a100e51b35e84556b430366b8..00b26e63c9622234fde13530c71b6579804f7033 100644 (file)
--- a/nmea.cc
+++ b/nmea.cc
@@ -35,6 +35,7 @@
 #include <ctime>
 
 #include <QtCore/QStringList>
+#include <QtCore/QThread>
 
 /**********************************************************
 
@@ -1229,7 +1230,7 @@ nmea_wayptpr(const Waypoint* wpt)
   gbfprintf(file_out, "$%s*%02X\n", obuf, cksum);
   if (sleepus >= 0) {
     gbfflush(file_out);
-    gb_sleep(sleepus);
+    QThread::usleep(sleepus);
   }
 }
 static void
@@ -1251,11 +1252,11 @@ nmea_trackpt_pr(const Waypoint* wpt)
     gbfflush(file_out);
     if (last_time > 0) {
       if (sleepus >= 0) {
-        gb_sleep(sleepus);
+        QThread::usleep(sleepus);
       } else {
         long wait_time = wpt->GetCreationTime().toTime_t() - last_time;
         if (wait_time > 0) {
-          gb_sleep(wait_time * 1000000);
+          QThread::usleep(wait_time * 1000000);
         }
       }
     }
@@ -1454,6 +1455,6 @@ void reset_sirf_to_nmea(int br)
   pkt[27] = br & 0xff;
 
   sirf_write(pkt);
-  gb_sleep(250 * 1000);
+  QThread::usleep(250 * 1000);
   gbser_flush(gbser_handle);
 }
index b712a9d609d516dac7d6b57fd4f88513dadb4cd0..5bbed2294e4943c591c4671f2f45395d40ea9427 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "defs.h"
 #include "gbser.h"
+#include <QtCore/QThread>
 #include <cmath>
 #include <cstdio>
 #include <cstdlib>
@@ -469,7 +470,7 @@ skytraq_set_baud(int baud)
     return res_ERROR;
   }
 
-  gb_sleep(50);                /* allow UART to settle. */
+  QThread::usleep(50);         /* allow UART to settle. */
 
   return res_OK;
 }
@@ -1206,7 +1207,7 @@ skytraq_probe()
       }
     }
 
-    gb_sleep(50);              /* allow UART to settle. */
+    QThread::usleep(50);               /* allow UART to settle. */
 
     skytraq_wr_msg(MSG_QUERY_SOFTWARE_VERSION, /* get firmware version */
                    sizeof(MSG_QUERY_SOFTWARE_VERSION));